﻿using System;
using System.Text;
using System.Threading;
using Mono.Collections.Generic;

namespace Mono.Cecil
{
	// Token: 0x0200009F RID: 159
	public class MethodReference : MemberReference, IMethodSignature, IMetadataTokenProvider, IGenericParameterProvider, IGenericContext
	{
		// Token: 0x17000168 RID: 360
		// (get) Token: 0x06000637 RID: 1591 RVA: 0x0002097C File Offset: 0x0001EB7C
		// (set) Token: 0x06000638 RID: 1592 RVA: 0x000044D0 File Offset: 0x000026D0
		public virtual bool HasThis
		{
			get
			{
				return this.has_this;
			}
			set
			{
				this.has_this = value;
			}
		}

		// Token: 0x17000169 RID: 361
		// (get) Token: 0x06000639 RID: 1593 RVA: 0x00020994 File Offset: 0x0001EB94
		// (set) Token: 0x0600063A RID: 1594 RVA: 0x000044DA File Offset: 0x000026DA
		public virtual bool ExplicitThis
		{
			get
			{
				return this.explicit_this;
			}
			set
			{
				this.explicit_this = value;
			}
		}

		// Token: 0x1700016A RID: 362
		// (get) Token: 0x0600063B RID: 1595 RVA: 0x000209AC File Offset: 0x0001EBAC
		// (set) Token: 0x0600063C RID: 1596 RVA: 0x000044E4 File Offset: 0x000026E4
		public virtual MethodCallingConvention CallingConvention
		{
			get
			{
				return this.calling_convention;
			}
			set
			{
				this.calling_convention = value;
			}
		}

		// Token: 0x1700016B RID: 363
		// (get) Token: 0x0600063D RID: 1597 RVA: 0x000209C4 File Offset: 0x0001EBC4
		public virtual bool HasParameters
		{
			get
			{
				return !this.parameters.IsNullOrEmpty<ParameterDefinition>();
			}
		}

		// Token: 0x1700016C RID: 364
		// (get) Token: 0x0600063E RID: 1598 RVA: 0x000209E4 File Offset: 0x0001EBE4
		public virtual Collection<ParameterDefinition> Parameters
		{
			get
			{
				bool flag = this.parameters == null;
				if (flag)
				{
					Interlocked.CompareExchange<ParameterDefinitionCollection>(ref this.parameters, new ParameterDefinitionCollection(this), null);
				}
				return this.parameters;
			}
		}

		// Token: 0x1700016D RID: 365
		// (get) Token: 0x0600063F RID: 1599 RVA: 0x00020A1C File Offset: 0x0001EC1C
		IGenericParameterProvider IGenericContext.Type
		{
			get
			{
				TypeReference declaringType = this.DeclaringType;
				GenericInstanceType genericInstanceType = declaringType as GenericInstanceType;
				bool flag = genericInstanceType != null;
				IGenericParameterProvider result;
				if (flag)
				{
					result = genericInstanceType.ElementType;
				}
				else
				{
					result = declaringType;
				}
				return result;
			}
		}

		// Token: 0x1700016E RID: 366
		// (get) Token: 0x06000640 RID: 1600 RVA: 0x00020A50 File Offset: 0x0001EC50
		IGenericParameterProvider IGenericContext.Method
		{
			get
			{
				return this;
			}
		}

		// Token: 0x1700016F RID: 367
		// (get) Token: 0x06000641 RID: 1601 RVA: 0x00020A64 File Offset: 0x0001EC64
		GenericParameterType IGenericParameterProvider.GenericParameterType
		{
			get
			{
				return GenericParameterType.Method;
			}
		}

		// Token: 0x17000170 RID: 368
		// (get) Token: 0x06000642 RID: 1602 RVA: 0x00020A78 File Offset: 0x0001EC78
		public virtual bool HasGenericParameters
		{
			get
			{
				return !this.generic_parameters.IsNullOrEmpty<GenericParameter>();
			}
		}

		// Token: 0x17000171 RID: 369
		// (get) Token: 0x06000643 RID: 1603 RVA: 0x00020A98 File Offset: 0x0001EC98
		public virtual Collection<GenericParameter> GenericParameters
		{
			get
			{
				bool flag = this.generic_parameters == null;
				if (flag)
				{
					Interlocked.CompareExchange<Collection<GenericParameter>>(ref this.generic_parameters, new GenericParameterCollection(this), null);
				}
				return this.generic_parameters;
			}
		}

		// Token: 0x17000172 RID: 370
		// (get) Token: 0x06000644 RID: 1604 RVA: 0x00020AD0 File Offset: 0x0001ECD0
		// (set) Token: 0x06000645 RID: 1605 RVA: 0x00020AF8 File Offset: 0x0001ECF8
		public TypeReference ReturnType
		{
			get
			{
				MethodReturnType methodReturnType = this.MethodReturnType;
				return (methodReturnType != null) ? methodReturnType.ReturnType : null;
			}
			set
			{
				MethodReturnType methodReturnType = this.MethodReturnType;
				bool flag = methodReturnType != null;
				if (flag)
				{
					methodReturnType.ReturnType = value;
				}
			}
		}

		// Token: 0x17000173 RID: 371
		// (get) Token: 0x06000646 RID: 1606 RVA: 0x00020B20 File Offset: 0x0001ED20
		// (set) Token: 0x06000647 RID: 1607 RVA: 0x000044EE File Offset: 0x000026EE
		public virtual MethodReturnType MethodReturnType
		{
			get
			{
				return this.return_type;
			}
			set
			{
				this.return_type = value;
			}
		}

		// Token: 0x17000174 RID: 372
		// (get) Token: 0x06000648 RID: 1608 RVA: 0x00020B38 File Offset: 0x0001ED38
		public override string FullName
		{
			get
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append(this.ReturnType.FullName).Append(" ").Append(base.MemberFullName());
				this.MethodSignatureFullName(stringBuilder);
				return stringBuilder.ToString();
			}
		}

		// Token: 0x17000175 RID: 373
		// (get) Token: 0x06000649 RID: 1609 RVA: 0x00009C40 File Offset: 0x00007E40
		public virtual bool IsGenericInstance
		{
			get
			{
				return false;
			}
		}

		// Token: 0x17000176 RID: 374
		// (get) Token: 0x0600064A RID: 1610 RVA: 0x00020B88 File Offset: 0x0001ED88
		public override bool ContainsGenericParameter
		{
			get
			{
				bool flag = this.ReturnType.ContainsGenericParameter || base.ContainsGenericParameter;
				bool result;
				if (flag)
				{
					result = true;
				}
				else
				{
					bool flag2 = !this.HasParameters;
					if (flag2)
					{
						result = false;
					}
					else
					{
						Collection<ParameterDefinition> collection = this.Parameters;
						for (int i = 0; i < collection.Count; i++)
						{
							bool containsGenericParameter = collection[i].ParameterType.ContainsGenericParameter;
							if (containsGenericParameter)
							{
								return true;
							}
						}
						result = false;
					}
				}
				return result;
			}
		}

		// Token: 0x0600064B RID: 1611 RVA: 0x000044F8 File Offset: 0x000026F8
		internal MethodReference()
		{
			this.return_type = new MethodReturnType(this);
			this.token = new MetadataToken(TokenType.MemberRef);
		}

		// Token: 0x0600064C RID: 1612 RVA: 0x0000451E File Offset: 0x0000271E
		public MethodReference(string name, TypeReference returnType) : base(name)
		{
			Mixin.CheckType(returnType, Mixin.Argument.returnType);
			this.return_type = new MethodReturnType(this);
			this.return_type.ReturnType = returnType;
			this.token = new MetadataToken(TokenType.MemberRef);
		}

		// Token: 0x0600064D RID: 1613 RVA: 0x0000455B File Offset: 0x0000275B
		public MethodReference(string name, TypeReference returnType, TypeReference declaringType) : this(name, returnType)
		{
			Mixin.CheckType(declaringType, Mixin.Argument.declaringType);
			this.DeclaringType = declaringType;
		}

		// Token: 0x0600064E RID: 1614 RVA: 0x00020C08 File Offset: 0x0001EE08
		public virtual MethodReference GetElementMethod()
		{
			return this;
		}

		// Token: 0x0600064F RID: 1615 RVA: 0x00020C1C File Offset: 0x0001EE1C
		protected override IMemberDefinition ResolveDefinition()
		{
			return this.Resolve();
		}

		// Token: 0x06000650 RID: 1616 RVA: 0x00020C34 File Offset: 0x0001EE34
		public new virtual MethodDefinition Resolve()
		{
			ModuleDefinition module = this.Module;
			bool flag = module == null;
			if (flag)
			{
				throw new NotSupportedException();
			}
			return module.Resolve(this);
		}

		// Token: 0x040001C7 RID: 455
		internal ParameterDefinitionCollection parameters;

		// Token: 0x040001C8 RID: 456
		private MethodReturnType return_type;

		// Token: 0x040001C9 RID: 457
		private bool has_this;

		// Token: 0x040001CA RID: 458
		private bool explicit_this;

		// Token: 0x040001CB RID: 459
		private MethodCallingConvention calling_convention;

		// Token: 0x040001CC RID: 460
		internal Collection<GenericParameter> generic_parameters;
	}
}
